package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.Log;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.core.page.TableDataInfo;
import com.lakeworks.common.enums.BusinessType;
import com.lakeworks.domain.OprSource;
import com.lakeworks.service.IOprSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * sourceController
 *
 * @author lake
 * @date 2023-02-08
 */
@Controller
@RequestMapping("/system/source")
public class OprSourceController extends BaseController {
    private String prefix = "system/source";

    @Autowired
    private IOprSourceService oprSourceService;


    @GetMapping()
    public String source() {
        return prefix + "/source";
    }

    /**
     * 查询source列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OprSource oprSource) {
        startPage();
        List<OprSource> list = oprSourceService.selectOprSourceList(oprSource);
        return getDataTable(list);
    }

    /**
     * 导出source列表
     */

//    @Log(title = "source", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(OprSource oprSource)
//    {
//        List<OprSource> list = oprSourceService.selectOprSourceList(oprSource);
//        ExcelUtil<OprSource> util = new ExcelUtil<OprSource>(OprSource.class);
//        return util.exportExcel(list, "source数据");
//    }

    /**
     * 新增source
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存source
     */

    @Log(title = "source", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OprSource oprSource) {
        return toAjax(oprSourceService.insertOprSource(oprSource));
    }

    /**
     * 修改source
     */

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OprSource oprSource = oprSourceService.selectOprSourceById(id);
        mmap.put("oprSource", oprSource);
        return prefix + "/edit";
    }

    /**
     * 修改保存source
     */

    @Log(title = "source", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OprSource oprSource) {
        return toAjax(oprSourceService.updateOprSource(oprSource));
    }

    /**
     * 删除source
     */

    @Log(title = "source", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(oprSourceService.deleteOprSourceByIds(ids));
    }
}
